import 'dart:convert';

import 'package:amway_superapp_creator_plugin/analysis/zhuge_edit.dart';
import 'package:amway_superapp_creator_plugin/dialog/comm_tip_dialog.dart';
import 'package:amway_superapp_creator_plugin/dialog/common_bottom_sheet.dart';
import 'package:amway_superapp_creator_plugin/dialog/edit_phone_dialog.dart';
import 'package:amway_superapp_creator_plugin/dialog/loading_dialog.dart';
import 'package:amway_superapp_creator_plugin/models/guanfang_image.dart';
import 'package:amway_superapp_creator_plugin/net/http_manager.dart';
import 'package:amway_superapp_creator_plugin/routers/application.dart';
import 'package:amway_superapp_creator_plugin/routers/routes.dart';
import 'package:amway_superapp_creator_plugin/utils/oss_util.dart';
import 'package:amway_superapp_creator_plugin/utils/sp_util.dart';
import 'package:amway_superapp_creator_plugin/utils/throttle.dart';
import 'package:amway_superapp_creator_plugin/utils/toast_util.dart';
import 'package:amway_superapp_creator_plugin/widget/diver.dart';
import 'package:amway_superapp_creator_plugin/widget/swiper_pagination.dart';
import 'package:dio/dio.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_flavor/flutter_flavor.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:uuid/uuid.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
import '../../config/colors_config.dart';
import '../page_tag_list.dart';
import 'dy_number.dart';
import 'identity_label.dart';
import 'interest_label.dart';
import 'ks_number.dart';
import 'package:amway_superapp_creator_plugin/models/create_user_info_model.dart';
import 'package:amway_superapp_creator_plugin/utils/image_pickasset_util.dart';
import 'package:page_view_indicators/circle_page_indicator.dart';

//滚动最大距离
const APPBAR_SCROLL_OFFSET = 100;

class EditDataPage extends StatefulWidget {
  CreateUserInfoModel createUserInfoModel;
  String amwayAda;
  bool hasDraft;
  bool isFromLaunch;

  EditDataPage(this.amwayAda,
      {this.hasDraft, this.createUserInfoModel, this.isFromLaunch = false});

  @override
  _TabNavigatorState createState() => _TabNavigatorState();
}

class _TabNavigatorState extends State<EditDataPage> {
  String officialIconUrl =
      'https://ft2-creatorconf-oss.oss-cn-shenzhen.aliyuncs.com/Creators_As_20201023/PNG/A__Art- &-Crafts.png';

  FocusNode _focusNode = FocusNode();
  FocusNode _nickNode = FocusNode();
  FocusNode _wxNode = FocusNode();
  FocusNode _phoneNode = FocusNode();

  List<ImagesBean> _imageUrl = [];
  double appBarAlpha = 0;
  String nick = ""; //昵称
  String phone = ""; //手机号
  String introduction = ""; //简介
  bool isSubmit = false; //是否提交
  bool isChinese = false; //是否中文
  String wxCode = "";
  TextEditingController _nickController;
  TextEditingController _descController;
  TextEditingController _wxController;

  __onScroll(offset) {
    double alpha = offset / APPBAR_SCROLL_OFFSET;
    if (alpha < 0) {
      alpha = 0;
    } else if (alpha > 1) {
      alpha = 1;
    }
    setState(() {
      appBarAlpha = alpha;
    });
  }

  @override
  void dispose() {
    super.dispose();
    _focusNode.dispose();
    _nickNode.dispose();
    _wxNode.dispose();
    _phoneNode.dispose();
    widget.createUserInfoModel = null;
    _nickController.dispose();
    _wxController.dispose();
    _descController.dispose();
  }

  double dx = 150.00;

  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
        value: SystemUiOverlayStyle.dark,
        child: Scaffold(
          backgroundColor: Colors.white,
          body: WillPopScope(
            // ignore: missing_return
            onWillPop: () {
              _back();
            },
            child: GestureDetector(
              onTap: () {
                setFocus();
              },
              // behavior: HitTestBehavior.opaque,
              onPanDown: (_) {
                FocusScope.of(context).requestFocus(FocusNode());
              },
              child: Stack(
                children: <Widget>[
                  MediaQuery.removePadding(
                      context: context,
                      removeTop: true,
                      //监听列表的滚动
                      child: NotificationListener(
                        //监听滚动后要调用的方法
                        // ignore: missing_return
                        onNotification: (scrollNotification) {
                          //只有当是更新状态下和是第0个child的时候才会调用
                          if (scrollNotification is ScrollUpdateNotification &&
                              scrollNotification.depth == 0) {
                            if (scrollNotification.metrics.pixels <= 110) {
                              __onScroll(scrollNotification.metrics.pixels);
                            }
                          }
                        },
                        child: ListView(
                          children: <Widget>[
                            _top(),
                            _info(),
                            _lable(),
                            _contactDesc(),
                            _contactType(),
                          ],
                        ),
                      )),
                  //通过Opacity的透明度来控制appBar的显示与隐藏
                  // opacity:透明度，0.0 到 1.0，0.0表示完全透明，1.0表示完全不透明
                  Opacity(
                    opacity: appBarAlpha,
                    child: Container(
                      height: ScreenUtil().setHeight(100),
                      decoration: BoxDecoration(
                        color: Colors.white,
                      ),
                      child: Center(
                        child: Padding(
                          padding: EdgeInsets.only(top: 20),
                          child: Text(
                            "编辑资料",
                            style: TextStyle(
                                color: ColorsConfig.c_2c2c2c,
                                fontSize: ScreenUtil().setSp(18)),
                          ),
                        ),
                      ),
                    ),
                  ),
                  Opacity(
                    opacity: 1,
                    child: Container(
                        width: 50,
                        alignment: Alignment.centerLeft,
                        height: ScreenUtil().setHeight(100),
                        child: Center(
                            child: Padding(
                          padding: EdgeInsets.only(top: 20),
                          child: IconButton(
                            icon: Image.asset(
                              'picture/icon_back.png',
                              package: 'amway_superapp_creator_plugin',
                            ),
                            onPressed: () {
                              _back();
                            },
                          ),
                        ))),
                  )
                ],
              ),
            ),
          ),
          bottomNavigationBar: _save(),
        ));
  }

/*
* 返回弹窗
* */
  void _back() {
    setFocus();
    // if (nick.isEmpty) {
    //   setState(() {
    //     isSubmit = true;
    //   });
    //   ToastUtils.toast(context, msg: "输入昵称后才能开启创玩小站哦");
    //   return;
    // }
    SpUtil.getData("${SpUtil.local_user_data}${widget.amwayAda}").then((value) {
      Map<String, dynamic> response = json.decode(value);
      CreateUserInfoModel infoModel = CreateUserInfoModel.fromJson(response);
      if (widget.createUserInfoModel == infoModel) {
        Application.router.pop(context, 1);
      } else {
        showDialog(
            barrierDismissible: true,
            //是否点击空白区域关闭对话框,默认为true，可以关闭
            context: context,
            builder: (BuildContext context) {
              List<ItemMode> list = List<ItemMode>();
              list.add(ItemMode(
                  label: '将退出编辑，是否保存草稿？',
                  color: ColorsConfig.c_8f8f8f,
                  size: 15));
              list.add(ItemMode(
                  label: '保存草稿并退出', color: ColorsConfig.c_396E75, size: 17));
              list.add(ItemMode(
                  label: '继续编辑', color: ColorsConfig.c_396E75, size: 17));
              return CommonBottomSheet(
                list: list,
                onItemClickListener: (index) async {
                  Navigator.pop(context);
                  switch (index) {
                    case 2:
                      SpUtil.setData("${SpUtil.user_data}${widget.amwayAda}",
                          json.encode(widget.createUserInfoModel));
                      if (widget.isFromLaunch) {
                        Map<String, dynamic> parameters = {
                          'createUserInfoModel': widget.createUserInfoModel,
                          'amwayAda': widget.createUserInfoModel.ada,
                          'amwayId': widget.createUserInfoModel.amwayId,
                          'isFromLaunch': widget.isFromLaunch,
                        };
                        Application.router.pop(context, parameters);
                      } else {
                        Application.router.pop(context, 1);
                      }
                      if (wxCode != widget.createUserInfoModel.wxCode)
                        widget.createUserInfoModel.wxCode = wxCode;
                      break;
                  }
                },
              );
            });
      }
    });
  }

  /*
  * 照片
  * */
  void _photo() {
    setFocus();
    showDialog(
        barrierDismissible: true,
        //是否点击空白区域关闭对话框,默认为true，可以关闭
        context: context,
        builder: (BuildContext context) {
          List<ItemMode> list = List<ItemMode>();
          list.add(
              ItemMode(label: '查看图片', color: ColorsConfig.c_396E75, size: 17));
          list.add(
              ItemMode(label: '重新选择', color: ColorsConfig.c_396E75, size: 17));
          return CommonBottomSheet(
            list: list,
            onItemClickListener: (index) async {
              Navigator.pop(context);
              switch (index) {
                case 0:
                  Map<String, dynamic> parameters = {
                    'image': widget.createUserInfoModel.wxEnterpriseQRCode.data,
                  };
                  Application.router.navigateTo(context, Routes.LOOK_BIG_IMAGE,
                      routeSettings: RouteSettings(arguments: parameters),
                      transition: TransitionType.cupertino);
                  break;
                case 2:
                  choosePhoto();
                  break;
              }
            },
          );
        });
  }

/*
* 修改电话
* */
  void _editPhone() {
    setFocus();
    showDialog(
        barrierDismissible: true,
        //是否点击空白区域关闭对话框,默认为true，可以关闭
        context: context,
        builder: (BuildContext context) {
          return EditPhoneDialog(
            mobile: widget.createUserInfoModel.mobile != null
                ? widget.createUserInfoModel.mobile
                : "",
            confirmCallback: (mobile) {
              widget.createUserInfoModel.mobile = mobile;
              setState(() {});
            },
            dismissCallback: () {},
            outsideDismiss: true,
          );
        });
  }

  int nickState = 0; //昵称状态
  int introduceState = 0; //介绍状态
  int ksState = 0; //快手状态
  int dyState = 0; //抖音状态
  int wxState = 0; //微信状态
  double width = 0.0;

  @override
  void initState() {
    widget.amwayAda = widget.createUserInfoModel.ada;
    if (widget.createUserInfoModel.displayAudits != null) {
      setCoverStates();
      widget.createUserInfoModel.displayAudits.forEach((element) {
        switch (element.propertyNameTip) {
          case "PG_NICK": //昵称
            nickState = state(element.status);
            break;
          case "PG_COVER": //封面
            break;
          case "PG_INTRODUCE": //介绍
            introduceState = state(element.status);
            break;
          case "PG_KUAI_SHOU_QRCODE": //快手号
            ksState = state(element.status);
            break;
          case "PG_DOU_YIN_QRCODE": //抖音号
            dyState = state(element.status);
            break;
          case "PG_WX_ENTERPRISE_QRCODE": //微信号
            wxState = state(element.status);
            break;
        }
      });
    }
    wxCode = widget.createUserInfoModel.wxCode;
    _wxNode.addListener(() {
      if (!_wxNode.hasFocus) {
        if (isChinese) {
          ToastUtils.toast(context, msg: "微信号错误，请重新填写");
        }
      }
    });
    nick = widget.createUserInfoModel.nick != null
        ? widget.createUserInfoModel.nick
        : "";
    _nickController = TextEditingController(text: nick);
    _nickController.addListener(() {
      String current = _nickController.text;
      widget.createUserInfoModel.nick = current;
    });
    var introduce = widget.createUserInfoModel.introduce != null
        ? widget.createUserInfoModel.introduce
        : "";
    _descController = TextEditingController(text: introduce);
    _descController.addListener(() {
      String current = _descController.text;
      widget.createUserInfoModel.introduce = current;
    });

    _wxController = TextEditingController(text: wxCode);
    _wxController.addListener(() {
      String current = _wxController.text.trim();
      widget.createUserInfoModel.wxCode = current;
    });
    super.initState();
    ZhugeEditAnalysis.editPage(EditPageType.editPage);
  }

  int state(String status) {
    switch (status) {
      case "AUDITING": //审核中
        return 1;
        break;
      case "PASSED": //通过
        return 2;
        break;
      case "UN_PASS": //不通过
        return 3;
        break;
      default:
        return 4;
        break;
    }
  }

  Widget _save() {
    return Container(
        padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(16),
            ScreenUtil().setWidth(16),
            ScreenUtil().setWidth(16),
            ScreenUtil().setWidth(34)),
        decoration: BoxDecoration(color: Colors.white, boxShadow: [
          BoxShadow(
              color: ColorsConfig.c_26000000,
              offset: Offset(0.0, 2.0), //阴影xy轴偏移量
              blurRadius: 15.0, //阴影模糊程度
              spreadRadius: 0.0 //阴影扩散程度
              )
        ]),
        child: InkWell(
          onTap: throttle(() async {
            await Future.delayed(Duration(milliseconds: 1000));
            ZhugeEditAnalysis.editPageClickSave('资料编辑');
            _saveSubmit();
          }),
          child: Container(
              alignment: Alignment.center,
              child: Text(
                "保存并提交",
                style: TextStyle(
                    color: Colors.white, fontSize: ScreenUtil().setSp(18)),
              ),
              width: double.infinity,
              height: ScreenUtil().setWidth(50),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(25),
                  color: nick.isEmpty || isChinese == true
                      ? ColorsConfig.c_4d396E75
                      : ColorsConfig.leftBackColor)),
        ));
  }

  String hint = "";

  void _saveSubmit() {
    if (nick.isEmpty) {
      setState(() {
        isSubmit = true;
      });
      ToastUtils.toast(context, msg: "输入昵称后才能开启创玩小站哦");
      return;
    }
    if (isChinese == true) {
      return;
    }
    setFocus();
    hint = "";
    if (widget.createUserInfoModel.introduce == null ||
        widget.createUserInfoModel.introduce.isEmpty) {
      //简介
      hint = "简介、";
      jsIsNull = true;
    } else {
      if (widget.createUserInfoModel.introduce.length > 70) {
        ToastUtils.showShortToast("请修改字数超过限制的选项");
        return;
      }
    }
    if (widget.createUserInfoModel.identityMarks.length == 0) {
      hint += "身份标签、";
      sfIsNull = true;
    }
    if (widget.createUserInfoModel.interestMarks.length == 0) {
      hint += "兴趣标签、";
      xqIsNull = true;
    }
    if (widget.createUserInfoModel.wxCode == null ||
        widget.createUserInfoModel.wxCode.isEmpty) {
      hint += "微信号、";
      wxIsNull = true;
    }
    if (widget.createUserInfoModel.mobile == null ||
        widget.createUserInfoModel.mobile.isEmpty) {
      hint += "手机号、";
    }
    if (hint.isNotEmpty) {
      setState(() {});
      showDialog(
          context: context,
          barrierDismissible: false,
          builder: (_) {
            return CommTipDialog(
              isEditInfo: true,
              content: hint.endsWith("、") == true
                  ? hint.substring(0, hint.length - 1) + "尚未录入，录入后可帮助顾客更快地认识你。"
                  : hint + "尚未录入，录入后可帮助顾客更快地认识你。",
              confirmText: "继续编辑",
              closeText: "保存并提交",
              confirmCallback: () {
                changeHint();
              },
              dismissCallback: () {
                changeHint();
                _request();
              },
            );
          });
    } else {
      _request();
    }
  }

  changeHint() {
    Navigator.of(context).pop();
    jsIsNull = false;
    sfIsNull = false;
    xqIsNull = false;
    wxIsNull = false;
    setState(() {});
  }

  void _request() {
    if (isUserDraft) {
      //使用草稿清除本地数据
      SpUtil.clearData("${SpUtil.user_data}${widget.amwayAda}");
    } else {
      if (widget.hasDraft) {
        //未使用草稿 且有草稿
        SpUtil.clearData("${SpUtil.user_data}${widget.amwayAda}");
      }
    }
    showDialog(
      context: context,
      builder: (ctx) {
        return LoadingDialog(
          canceledOnTouchOutside: false,
          tipMsg: '正在保存中',
        );
      },
    );
    if (widget.createUserInfoModel.kuaiShouQRCode != null &&
        widget.createUserInfoModel.kuaiShouQRCode.data.isEmpty) {
      widget.createUserInfoModel.kuaiShouQRCode = null;
    }
    if (widget.createUserInfoModel.douYinQRCode != null &&
        widget.createUserInfoModel.douYinQRCode.data.isEmpty) {
      widget.createUserInfoModel.douYinQRCode = null;
    }
    if (widget.createUserInfoModel.wxEnterpriseQRCode != null &&
        widget.createUserInfoModel.wxEnterpriseQRCode.data.isEmpty) {
      widget.createUserInfoModel.wxEnterpriseQRCode = null;
    }
    if (widget.createUserInfoModel.personalSign == null) {
      widget.createUserInfoModel.personalSign =
          ImagesBean(data: officialIconUrl, dataType: "IMAGE");
    }
    if (widget.createUserInfoModel.id == null) {
      String url = "apis/v1/creator/personal-configs/${widget.amwayAda}}";
      HttpManager().post(
          url: url,
          data: widget.createUserInfoModel,
          tag: null,
          successCallback: (data) async {
            Application.router.pop(context);
            CreateUserInfoModel model = CreateUserInfoModel.fromJson(data);
            Navigator.pop(context, model);
            ToastUtils.showShortToast("保存成功");
          },
          errorCallback: (data) {
            Application.router.pop(context);
            ToastUtils.showShortToast(data.message);
          });
    } else {
      String url =
          "apis/v1/creator/personal-configs/${widget.createUserInfoModel.id}";
      HttpManager().put(
          url: url,
          data: widget.createUserInfoModel,
          tag: null,
          successCallback: (data) async {
            Application.router.pop(context);
            CreateUserInfoModel model = CreateUserInfoModel.fromJson(data);
            Navigator.pop(context, model);
            ToastUtils.showShortToast("保存成功");
          },
          errorCallback: (data) {
            Application.router.pop(context);
            ToastUtils.showShortToast(data.message);
          });
    }
  }

  String head = "";

/*
* 顶部内容
* */
  int current = 1;

  Widget _top() {
    if (width == 0.0) {
      width = MediaQuery.of(context).size.width;
    }
    return Stack(
      children: [
        _swiper(),
        _swiperBg(),
        _editCover(callback: () {
          ZhugeEditAnalysis.editCoverClickPage('个人资料页');
          setFocus();
          Map<String, dynamic> parameters = {
            'amwayAda': widget.amwayAda,
            'coverList': widget.createUserInfoModel.coverList
          };

          Application.router
              .navigateTo(context, Routes.setUserCover,
                  routeSettings: RouteSettings(arguments: parameters))
              .then((value) {
            if (value != null && value is List) {
              widget.createUserInfoModel.coverList = value;
              setState(() {
                _imageUrl = value;
              });
            }
          });
        }),
        Positioned(
            left: width / 2 - ScreenUtil().setWidth(53),
            right: width / 2 - ScreenUtil().setWidth(53),
            bottom: ScreenUtil().setWidth(50),
            child: _head(callback: () {
              setFocus();
              _navigateToChooseIcon();
            })),
        Positioned(
            bottom: ScreenUtil().setWidth(75),
            right: ScreenUtil().setWidth(2),
            child: _num(current, _imageUrl.length)),
        Positioned(
            bottom: ScreenUtil().setWidth(70),
            right: ScreenUtil().setWidth(2),
            child: _buildPageViewIndicator()),
        widget.hasDraft == true ? _userDraft() : Container()
      ],
    );
  }

  void _navigateToChooseIcon() {
    if (widget.createUserInfoModel.personalSign != null &&
        widget.createUserInfoModel.personalSign.data != null) {
      officialIconUrl = widget.createUserInfoModel.personalSign.data;
    }
    if (officialIconUrl == null) {
      officialIconUrl =
          'https://ft2-creatorconf-oss.oss-cn-shenzhen.aliyuncs.com/Creators_As_20201023/PNG/A__Art- &-Crafts.png';
    }
    Application.router
        .navigateTo(context, Routes.userIcon,
            routeSettings: RouteSettings(arguments: officialIconUrl))
        .then((value) => {
              if (value != null && value is String)
                {
                  setState(() {
                    officialIconUrl = value;
                    widget.createUserInfoModel.personalSign =
                        ImagesBean(data: officialIconUrl, dataType: "IMAGE");
                  })
                }
            });
  }

  void setFocus() {
    if (_focusNode.hasFocus) _focusNode.unfocus();
    if (_nickNode.hasFocus) _nickNode.unfocus();
    if (_wxNode.hasFocus) _wxNode.unfocus();
    if (_phoneNode.hasFocus) _phoneNode.unfocus();
  }

/*
* 审核状态
* */
  Widget _verify(String data) {
    return Container(
        child: coverState(data) == 1
            ? Image.asset(
                "picture/icon_under_review.png",
                package: 'amway_superapp_creator_plugin',
                width: ScreenUtil().setWidth(80),
                height: ScreenUtil().setWidth(30),
              )
            : coverState(data) == 3
                ? Image.asset(
                    "picture/icon_audit_nopass.png",
                    package: 'amway_superapp_creator_plugin',
                    width: ScreenUtil().setWidth(80),
                    height: ScreenUtil().setWidth(30),
                  )
                : Text(""));
  }

  int coverState(String data) {
    int cover = 0;
    if (widget.createUserInfoModel.displayAudits != null)
      widget.createUserInfoModel.displayAudits.forEach((element) {
        if (data == element.data) {
          if (element.propertyNameTip == "PG_COVER") {
            cover = state(element.status);
          }
        }
      });
    return cover;
  }

  void setCoverStates() {
    if (widget.createUserInfoModel.coverList != null)
      widget.createUserInfoModel.coverList.forEach((imagesBean) {
        if (imagesBean.officialFlag == "NO") {
          imagesBean.state = coverState(imagesBean.data);
        }
      });
  }

/*
* banner数字
* */
  Widget _num(int current, int total) {
    return total < 2
        ? Container()
        : Container(
            alignment: Alignment.lerp(
                Alignment.centerRight, Alignment.bottomRight, 0.5),
            margin: EdgeInsets.only(right: ScreenUtil().setWidth(10)),
            child: Text(
              "$current/$total",
              style: TextStyle(
                  color: Colors.white, fontSize: ScreenUtil().setSp(14)),
            ),
          );
  }

/*
* 头像
* */
  Widget _head({GestureTapCallback callback}) {
    return GestureDetector(
      onTap: callback,
      child: Stack(
        alignment: Alignment.center,
        children: [
          Container(
            alignment: Alignment.center,
            width: ScreenUtil().setWidth(106),
            height: ScreenUtil().setWidth(106),
            decoration: BoxDecoration(
              color: ColorsConfig.c_33D5D5D5,
              borderRadius:
                  BorderRadius.all(Radius.circular(ScreenUtil().setWidth(53))),
              border: Border.all(
                  width: ScreenUtil().setWidth(5), style: BorderStyle.none),
            ),
            child: Text(""),
          ),
          Stack(alignment: const Alignment(0.0, 1.0), children: [
            Container(
              alignment: Alignment.center,
              width: ScreenUtil().setWidth(100),
              height: ScreenUtil().setWidth(100),
              child: CircleAvatar(
                radius: ScreenUtil().setWidth(50),
                backgroundImage: NetworkImage(
                    widget.createUserInfoModel.personalSign != null
                        ? widget.createUserInfoModel.personalSign.data
                        : officialIconUrl),
                backgroundColor: Colors.white,
              ),
            ),
            ClipRect(
                child: Align(
              alignment: Alignment.bottomCenter,
              heightFactor: 0.32,
              child: Container(
                padding: EdgeInsets.only(bottom: ScreenUtil().setWidth(6)),
                alignment: Alignment.bottomCenter,
                width: ScreenUtil().setWidth(100),
                height: ScreenUtil().setWidth(100),
                decoration: BoxDecoration(
                  color: ColorsConfig.c_4D000000,
                  borderRadius: BorderRadius.all(
                      Radius.circular(ScreenUtil().setWidth(50))),
                ),
                child: Text(
                  '编辑',
                  style: new TextStyle(
                    fontSize: ScreenUtil().setSp(14),
                    color: Colors.white,
                  ),
                ),
              ),
            )),
          ])
        ],
      ),
    );
  }

  Widget _swiperBg() {
    return Positioned(
        bottom: 0,
        child: Container(
          width: ScreenUtil().screenWidth,
          child: Image.asset("picture/icon_info_cover_bg.png",
              width: ScreenUtil().screenWidth,
              fit: BoxFit.fitWidth,
              package: 'amway_superapp_creator_plugin'),
        ));
  }

/*
* 封面
* */
  Widget _swiper() {
    _imageUrl = widget.createUserInfoModel.coverList == null
        ? []
        : widget.createUserInfoModel.coverList;
    return Container(
      height: ScreenUtil().setWidth(width * (4 / 3)),
      child: _imageUrl.length > 0
          ? Swiper(
              //item的数量
              itemCount: _imageUrl.length,
              loop: _imageUrl.length > 1 ? true : false,
              //自动播放
              autoplay: false,
              itemBuilder: (BuildContext context, int index) {
                return Stack(
                  fit: StackFit.expand,
                  children: [
                    Image.network(
                      _imageUrl[index].data,
                      width: ScreenUtil().setWidth(width),
                      fit: BoxFit.fill,
                    ),
                    _verify(_imageUrl[index].data)
                  ],
                );
              },
              //banner上添加指示器
              pagination: _imageUrl.length > 1
                  ? SwiperPagination(
                      margin: EdgeInsets.only(bottom: 0, right: 0),
                      builder: SquareSwiperPagination(
                        size: 0,
                        activeSize: 0,
                        color: Colors.transparent,
                        activeColor: Colors.transparent,
                      ),
                      alignment: Alignment.lerp(
                          Alignment.centerRight, Alignment.bottomRight, 0.8),
                    )
                  : null,
              onIndexChanged: (index) {
                setState(() {
                  current = index + 1;
                });
              },
            )
          : Image.network(
              "https://www.amway.com.cn/content/dam/china/accl/amwaychina/news/photos/06151/01/big/9.JPG",
              fit: BoxFit.cover,
            ),
    );
  }

  //指示器
  _buildPageViewIndicator() {
    if (_imageUrl.length > 1) {
      return Container(
        margin: EdgeInsets.only(right: ScreenUtil().setWidth(10)),
        height: ScreenUtil().setWidth(2),
        child: ListView.builder(
            shrinkWrap: true,
            itemCount: _imageUrl.length,
            scrollDirection: Axis.horizontal,
            itemBuilder: (context, index) {
              return Container(
                decoration: BoxDecoration(
                  color: current == index + 1
                      ? Colors.white
                      : ColorsConfig.c_33ffffff,
                  borderRadius: BorderRadius.all(
                      Radius.circular(ScreenUtil().setWidth(2))),
                ),
                margin: EdgeInsets.only(left: ScreenUtil().setWidth(5)),
                width: ScreenUtil().setWidth(20),
                child: Text(""),
                height: ScreenUtil().setWidth(2),
              );
            }),
      );
    } else {
      return Container(height: 0, width: 0);
    }
  }

/*
* 编辑封面
* */
  Widget _editCover({VoidCallback callback}) {
    return Container(
      alignment: Alignment.topRight,
      margin: EdgeInsets.only(top: ScreenUtil().setHeight(150)),
      height: ScreenUtil().setHeight(35),
      child: RaisedButton(
        color: Color(0xCC000000),
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(ScreenUtil().setSp(50)),
                bottomLeft: Radius.circular(ScreenUtil().setSp(50)),
                bottomRight: Radius.circular(0),
                topRight: Radius.circular(0))),
        onPressed: callback,
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              margin: EdgeInsets.only(right: ScreenUtil().setWidth(5)),
              child: Image.asset(
                "picture/icon_edit_cover.png",
                color: Colors.white,
                package: 'amway_superapp_creator_plugin',
                width: ScreenUtil().setWidth(20),
                height: ScreenUtil().setWidth(20),
              ),
            ),
            Text("编辑封面",
                style: TextStyle(
                    color: Colors.white, fontSize: ScreenUtil().setSp(14)))
          ],
        ),
      ),
    );
  }

  /*
  * 个人信息
  * */
  Widget _info() {
    return Container(
        margin: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(16),
            ScreenUtil().setHeight(12),
            ScreenUtil().setWidth(16),
            ScreenUtil().setWidth(12)),
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(12),
            boxShadow: [
              BoxShadow(
                  color: ColorsConfig.c_14000000,
                  offset: Offset(0.0, 0.0), //阴影xy轴偏移量
                  blurRadius: 12.0, //阴影模糊程度
                  spreadRadius: 0.0 //阴影扩散程度
                  )
            ]),
        child: Column(
          children: [_nick(), Divide(), _introduction()],
        ));
  }

/*
* 昵称
* */
  bool nickChoose = true;

  Widget _nick() {
    return Row(children: [
      Container(
        margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(16),
            ScreenUtil().setWidth(17), 0, ScreenUtil().setWidth(17)),
        child: Text("昵称",
            style: TextStyle(
                fontWeight: FontWeight.bold,
                color: ColorsConfig.c_2c2c2c,
                fontSize: ScreenUtil().setSp(16))),
      ),
      Expanded(
        flex: 1,
        child: TextField(
          onTap: () {
            nickChoose = true;
          },
          keyboardAppearance: Brightness.light,
          style: TextStyle(
              fontSize: ScreenUtil().setSp(16),
              color: nickState == 3 ? ColorsConfig.c_cd0000 : Colors.black),
          decoration: InputDecoration(
            hintStyle: TextStyle(
                fontSize: ScreenUtil().setSp(16),
                color: isSubmit == true && nick.isEmpty
                    ? ColorsConfig.c_cd0000
                    : ColorsConfig.c_4D000000),
            hintText: "请输入昵称，可以使用表情图标",
            border: InputBorder.none,
            fillColor: Colors.transparent,
            filled: true,
          ),
          inputFormatters: [
            LengthLimitingTextInputFormatter(20) //限制长度
          ],
          focusNode: _nickNode,
          enabled: nickState != 1,
          controller: _nickController,
          onChanged: (value) {
            isSubmit = false;
            nick = value;
            if (nickState == 3) {
              //审核不通过时编辑后不显示审核状态
              nickState = 0;
            }
            // var byte = utf8.encode(value.toString());
            // print("长度：${byte.length}");
            setState(() {});
          },
        ),
      ),
      GestureDetector(
        onPanDown: (_) {
          nick = "";
          _nickController.clear();
        },
        child: Container(
          margin: EdgeInsets.only(right: ScreenUtil().setWidth(15)),
          child: _nickNode.hasFocus == true &&
                  widget.createUserInfoModel.nick != null &&
                  widget.createUserInfoModel.nick.length > 0
              ? Icon(
                  Icons.cancel,
                  size: ScreenUtil().setSp(25),
                  color: Colors.black45,
                )
              : Text(""),
        ),
      ),
      Container(
          margin: nickState == 1 || nickState == 3
              ? EdgeInsets.only(right: ScreenUtil().setWidth(10))
              : EdgeInsets.all(0),
          child: nickState == 1
              ? Image.asset(
                  "picture/icon_under_review.png",
                  package: 'amway_superapp_creator_plugin',
                  width: ScreenUtil().setWidth(80),
                  height: ScreenUtil().setWidth(30),
                )
              : nickState == 3
                  ? Image.asset(
                      "picture/icon_audit_nopass.png",
                      package: 'amway_superapp_creator_plugin',
                      width: ScreenUtil().setWidth(80),
                      height: ScreenUtil().setWidth(30),
                    )
                  : Text(""))
    ]);
  }

  bool wxIsNull = false;
  RegExp regexp = RegExp(
      "[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]");
  RegExp space = RegExp("[^\\S]");
  bool wxChoose = true;

  Widget _wx() {
    return Row(children: [
      Container(
        margin: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(16),
            ScreenUtil().setWidth(17),
            ScreenUtil().setWidth(6),
            ScreenUtil().setWidth(17)),
        child: Text("微信号",
            style: TextStyle(
                fontWeight: FontWeight.bold,
                color: ColorsConfig.c_2c2c2c,
                fontSize: ScreenUtil().setSp(16))),
      ),
      Expanded(
          flex: 1,
          child: TextField(
            onTap: () {
              wxChoose = true;
            },
            keyboardAppearance: Brightness.light,
            style: TextStyle(
                fontSize: ScreenUtil().setSp(16),
                color:
                    isChinese == true ? ColorsConfig.c_cd0000 : Colors.black),
            decoration: InputDecoration(
              hintStyle: TextStyle(
                  fontSize: ScreenUtil().setSp(16),
                  color: wxIsNull == true
                      ? ColorsConfig.c_cd0000
                      : ColorsConfig.c_4D000000),
              hintText: "输入微信号",
              border: InputBorder.none,
              fillColor: Colors.transparent,
              filled: true,
            ),
            inputFormatters: [
              FilteringTextInputFormatter.deny(regexp),
              FilteringTextInputFormatter.deny(space),
              LengthLimitingTextInputFormatter(30) //限制长度
            ],
            focusNode: _wxNode,
            controller: _wxController,
            onChanged: (value) {
              if (wxIsNull) wxIsNull = false;
              if (RegExp(r"[\u4e00-\u9fa5]").hasMatch(value.trim())) {
                isChinese = true;
                return;
              }
              setState(() {
                isChinese = false;
              });
            },
          )),
      GestureDetector(
        onPanDown: (_) {
          isChinese = false;
          _wxController.clear();
        },
        child: Container(
          margin: EdgeInsets.only(right: ScreenUtil().setWidth(15)),
          child: _wxNode.hasFocus == true && _wxController.text.length > 0
              ? Icon(
                  Icons.cancel,
                  size: ScreenUtil().setSp(25),
                  color: Colors.black45,
                )
              : Text(""),
        ),
      )
      // Container(
      //     margin: EdgeInsets.only(right: ScreenUtil().setWidth(20)),
      //     child: Text(
      //       "审核不通过",
      //       style:
      //           TextStyle(color: Colors.red, fontSize: ScreenUtil().setSp(16)),
      //     ))
    ]);
  }

/*
* 简介
* */
  bool jsIsNull = false;
  bool jsChoose = true;

  Widget _introduction() {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
            padding: EdgeInsets.fromLTRB(ScreenUtil().setWidth(16),
                ScreenUtil().setHeight(17), ScreenUtil().setWidth(16), 0),
            child: Text("简介",
                style: TextStyle(
                    fontWeight: FontWeight.bold,
                    color: const Color(0xFF2C2C2C),
                    fontSize: ScreenUtil().setSp(16)))),
        Expanded(
            flex: 1,
            child: Column(
              children: [
                Container(
                    padding: EdgeInsets.fromLTRB(0, ScreenUtil().setHeight(17),
                        ScreenUtil().setWidth(20), ScreenUtil().setHeight(19)),
                    child: TextField(
                      onTap: () {
                        jsChoose = true;
                      },
                      keyboardAppearance: Brightness.light,
                      enabled: introduceState != 1,
                      controller: _descController,
                      focusNode: _focusNode,
                      style: TextStyle(
                          fontSize: ScreenUtil().setSp(16),
                          color: introduceState == 3 ||
                                  widget.createUserInfoModel.introduce.length >
                                      70
                              ? ColorsConfig.c_cd0000
                              : ColorsConfig.c_000000),
                      decoration: InputDecoration(
                          border: InputBorder.none,
                          contentPadding:
                              const EdgeInsets.symmetric(vertical: 0.0),
                          hintText: '做一段自我介绍，让顾客好友们迅速地了解你吧',
                          hintStyle: TextStyle(
                              color: jsIsNull == false
                                  ? Color(0x4D000000)
                                  : ColorsConfig.c_cd0000,
                              fontSize: ScreenUtil().setSp(16)),
                          hintMaxLines: 2),
                      maxLines: 4,
                      onChanged: (text) {
                        setState(() {
                          introduction = text;
                          widget.createUserInfoModel.introduce = text;
                          if (introduceState == 3) {
                            introduceState = 0;
                          }
                          jsIsNull = false;
                        });
                      },
                    )),
                Container(
                  alignment: Alignment.topRight,
                  padding: EdgeInsets.only(
                      right: ScreenUtil().setWidth(20),
                      top: ScreenUtil().setHeight(5),
                      bottom: ScreenUtil().setHeight(5)),
                  width: double.infinity,
                  child: introduceState == 1
                      ? Image.asset(
                          "picture/icon_under_review.png",
                          package: 'amway_superapp_creator_plugin',
                          width: ScreenUtil().setWidth(80),
                          height: ScreenUtil().setWidth(30),
                        )
                      : introduceState == 3
                          ? Image.asset(
                              "picture/icon_audit_nopass.png",
                              package: 'amway_superapp_creator_plugin',
                              width: ScreenUtil().setWidth(80),
                              height: ScreenUtil().setWidth(30),
                            )
                          : Text(
                              '${widget.createUserInfoModel.introduce != null ? widget.createUserInfoModel.introduce.length : 0}/70',
                              textAlign: TextAlign.right,
                              style: TextStyle(
                                  fontSize: ScreenUtil().setSp(14),
                                  color: widget.createUserInfoModel.introduce !=
                                              null &&
                                          widget.createUserInfoModel.introduce
                                                  .length >
                                              70
                                      ? ColorsConfig.c_cd0000
                                      : ColorsConfig.c_4D2C2C2C),
                            ),
                )
              ],
            ))
      ],
    );
  }

/*
* 标签
* */
  bool sfIsNull = false;
  bool xqIsNull = false;

  Widget _lable() {
    return Container(
        margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(16), 0,
            ScreenUtil().setWidth(16), ScreenUtil().setHeight(12)),
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(12),
            boxShadow: [
              BoxShadow(
                  color: ColorsConfig.c_14000000,
                  offset: Offset(0.0, 0.0), //阴影xy轴偏移量
                  blurRadius: 12.0, //阴影模糊程度
                  spreadRadius: 0.0 //阴影扩散程度
                  )
            ]),
        child: Column(children: [
          IdentityLabel(
            setIdentity(),
            sfIsNull,
            callback: () {
              setFocus();
              sfIsNull = false;
              _navToIdentity();
            },
          ),
          Divide(),
          InterestLabel(setInterest(), xqIsNull, callback: () {
            setFocus();
            sfIsNull = false;
            _navToInterest();
          })
        ]));
  }

  _navToIdentity() async {
    List<String> cachedMarks = [];
    if (widget.createUserInfoModel.identityMarks != null) {
      cachedMarks.addAll(widget.createUserInfoModel.identityMarks);
    }
    List<String> identity = await Navigator.push(context,
        MaterialPageRoute(builder: (context) => TagListPage("0", cachedMarks)));
    if (identity == null) {
      return;
    }
    if (widget.createUserInfoModel.identityMarks != null) {
      widget.createUserInfoModel.identityMarks = identity;
    }
    setState(() {});
  }

/*
* 设置身份标签
* */
  List<Widget> setIdentity() {
    List<Widget> identityList = [];
    if (widget.createUserInfoModel.identityMarks != null)
      widget.createUserInfoModel.identityMarks.forEach((element) {
        identityList.add(_label(element));
      });
    return identityList;
  }

/*
* 设置兴趣标签
* */
  List<Widget> setInterest() {
    List<Widget> interestList = [];
    if (widget.createUserInfoModel.interestMarks != null)
      widget.createUserInfoModel.interestMarks.forEach((element) {
        interestList.add(_label(element));
      });
    return interestList;
  }

  _navToInterest() async {
    List<String> cachedMarks = [];
    if (widget.createUserInfoModel.interestMarks != null) {
      cachedMarks.addAll(widget.createUserInfoModel.interestMarks);
    }
    List<String> interest = await Navigator.push(context,
        MaterialPageRoute(builder: (context) => TagListPage("1", cachedMarks)));
    if (interest == null) {
      return;
    }
    if (widget.createUserInfoModel.interestMarks != null)
      widget.createUserInfoModel.interestMarks = interest;
    setState(() {});
  }

  Widget _label(String content) {
    return Container(
      alignment: Alignment.center,
      margin: EdgeInsets.only(left: ScreenUtil().setWidth(10)),
      padding: EdgeInsets.fromLTRB(
          ScreenUtil().setWidth(9),
          ScreenUtil().setWidth(2),
          ScreenUtil().setWidth(9),
          ScreenUtil().setWidth(2)),
      decoration: BoxDecoration(
          color: ColorsConfig.c_e6e9f7f8,
          borderRadius: BorderRadius.all(Radius.circular(11))),
      child: Text(content,
          style: TextStyle(
              color: Color(0xff396E75), fontSize: ScreenUtil().setSp(12))),
    );
  }

  Widget _contactDesc() {
    return Container(
      width: double.infinity,
      margin: EdgeInsets.fromLTRB(ScreenUtil().setHeight(16),
          ScreenUtil().setHeight(40), 0, ScreenUtil().setHeight(10)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text("联系方式",
              style: TextStyle(
                  fontWeight: FontWeight.bold,
                  color: const Color(0xFF2C2C2C),
                  fontSize: ScreenUtil().setSp(18))),
          Text("让顾客以最便捷的方式找到你",
              style: TextStyle(
                  color: const Color(0x4D000000),
                  fontSize: ScreenUtil().setSp(12)))
        ],
      ),
    );
  }

  /*
  * 微信二维码
  * */
  String enterpriseCode = "";

  Widget _input(String title, String hint) {
    return GestureDetector(
      child: Row(
        children: [
          Container(
            margin: EdgeInsets.fromLTRB(
                ScreenUtil().setWidth(16),
                ScreenUtil().setWidth(16),
                ScreenUtil().setWidth(20),
                ScreenUtil().setWidth(16)),
            child: Text(title,
                style: TextStyle(
                    fontWeight: FontWeight.bold,
                    color: const Color(0xFF2C2C2C),
                    fontSize: ScreenUtil().setSp(16))),
          ),
          Expanded(flex: 1, child: Text("")),
          wxState == 1
              ? Image.asset(
                  "picture/icon_under_review.png",
                  package: 'amway_superapp_creator_plugin',
                  width: ScreenUtil().setWidth(80),
                  height: ScreenUtil().setWidth(30),
                )
              : wxState == 3
                  ? Image.asset(
                      "picture/icon_audit_nopass.png",
                      package: 'amway_superapp_creator_plugin',
                      width: ScreenUtil().setWidth(80),
                      height: ScreenUtil().setWidth(30),
                    )
                  : Text(""),
          widget.createUserInfoModel.wxEnterpriseQRCode != null &&
                  widget.createUserInfoModel.wxEnterpriseQRCode.data != null &&
                  widget.createUserInfoModel.wxEnterpriseQRCode.data.isNotEmpty
              ? Container(
                  width: ScreenUtil().setWidth(35),
                  height: ScreenUtil().setWidth(35),
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                      color: ColorsConfig.c_F7F7F7,
                      border: Border.all(
                          color: ColorsConfig.c_d8d8d8,
                          width: ScreenUtil().setWidth(0.5)),
                      borderRadius: BorderRadius.circular(4),
                      boxShadow: [
                        BoxShadow(
                            color: ColorsConfig.c_14000000,
                            offset: Offset(0.0, 0.0), //阴影xy轴偏移量
                            blurRadius: 12.0, //阴影模糊程度
                            spreadRadius: 0.0 //阴影扩散程度
                            )
                      ]),
                  child: Image.network(
                    widget.createUserInfoModel.wxEnterpriseQRCode.data != null
                        ? widget.createUserInfoModel.wxEnterpriseQRCode.data
                        : "",
                    fit: BoxFit.fill,
                    width: ScreenUtil().setWidth(28),
                    height: ScreenUtil().setWidth(28),
                  ))
              : enterpriseCode.isEmpty
                  ? Text(
                      hint,
                      textAlign: TextAlign.end,
                      style: TextStyle(
                          color: Color(0x4D000000),
                          fontSize: ScreenUtil().setSp(16)),
                    )
                  : Container(
                      width: ScreenUtil().setWidth(35),
                      height: ScreenUtil().setWidth(35),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          color: ColorsConfig.c_F7F7F7,
                          border: Border.all(
                              color: ColorsConfig.c_d8d8d8,
                              width: ScreenUtil().setWidth(0.5)),
                          borderRadius: BorderRadius.circular(4),
                          boxShadow: [
                            BoxShadow(
                                color: ColorsConfig.c_14000000,
                                offset: Offset(0.0, 0.0), //阴影xy轴偏移量
                                blurRadius: 12.0, //阴影模糊程度
                                spreadRadius: 0.0 //阴影扩散程度
                                )
                          ]),
                      child: Image.network(
                        enterpriseCode,
                        fit: BoxFit.fill,
                        width: ScreenUtil().setWidth(28),
                        height: ScreenUtil().setWidth(28),
                      )),
          Container(
              margin: EdgeInsets.only(
                  left: ScreenUtil().setWidth(5),
                  right: ScreenUtil().setWidth(12)),
              child: Image.asset(
                'picture/icon_right.png',
                package: 'amway_superapp_creator_plugin',
              ))
        ],
      ),
      onTap: () {
        if (wxState == 1) {
          return;
        }
        if (widget.createUserInfoModel.wxEnterpriseQRCode != null &&
            widget.createUserInfoModel.wxEnterpriseQRCode.data.isNotEmpty) {
          _photo();
          return;
        }
        choosePhoto();
      },
    );
  }

  void choosePhoto() {
    setFocus();
    pickAsset(context, RequestType.image, maxAssetsCount: 1,isCanEdite: false).then((value) {
      if (value == null) {
        return;
      }
      showDialog(
        context: context,
        builder: (ctx) {
          return LoadingDialog(
            canceledOnTouchOutside: false,
            tipMsg: '正在上传中',
          );
        },
      );
      value.first.file.then((value) {
        OssHelper.getOssConfiguration().then((result) {
          Map<String, dynamic> ossMsg = {
            "accessKeyId": result.data['data']['accessKeyId'],
            "accessKeySecret": result.data['data']['accessKeySecret'],
            "expiration": result.data['data']['expiration'],
            "securityToken": result.data['data']['securityToken']
          };
          OssHelper.uploadToOss(value, ossMsg).then((value) {
            setState(() {
              this.enterpriseCode = value;
              widget.createUserInfoModel.wxEnterpriseQRCode = ImagesBean(
                  data: value, officialFlag: "NO", dataType: "IMAGE");
              Application.router.pop(context);
            });
          });
        });
      });
    });
  }

  Widget _phone(String title, String hint) {
    return GestureDetector(
      child: Row(
        children: [
          Container(
            margin: EdgeInsets.fromLTRB(
                ScreenUtil().setWidth(16),
                ScreenUtil().setWidth(16),
                ScreenUtil().setWidth(20),
                ScreenUtil().setWidth(16)),
            child: Text(title,
                style: TextStyle(
                    fontWeight: FontWeight.bold,
                    color: const Color(0xFF2C2C2C),
                    fontSize: ScreenUtil().setSp(16))),
          ),
          Expanded(
              flex: 1,
              child: widget.createUserInfoModel.mobile == null ||
                      widget.createUserInfoModel.mobile == ""
                  ? Text("输入手机号",
                      textAlign: TextAlign.start,
                      style: TextStyle(
                          color: Color(0x4D000000),
                          fontSize: ScreenUtil().setSp(16)))
                  : Text(
                      widget.createUserInfoModel.mobile,
                      textAlign: TextAlign.start,
                      style: TextStyle(
                          color: ColorsConfig.c_000000,
                          fontSize: ScreenUtil().setSp(16)),
                    )),
          InkWell(
            onTap: () {
              _editPhone();
            },
            child: Text(
              hint,
              textAlign: TextAlign.end,
              style: TextStyle(
                  color: Color(0x4D000000), fontSize: ScreenUtil().setSp(16)),
            ),
          ),
          Container(
              margin: EdgeInsets.only(
                  left: ScreenUtil().setWidth(5),
                  right: ScreenUtil().setWidth(12)),
              child: Image.asset(
                'picture/icon_right.png',
                package: 'amway_superapp_creator_plugin',
              ))
        ],
      ),
      onTap: () {
        setFocus();
      },
    );
  }

  /*
  * 联系方式
  * */
  Widget _contactType() {
    return Container(
      margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(16), 0,
          ScreenUtil().setWidth(16), ScreenUtil().setWidth(12)),
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(12),
          boxShadow: [
            BoxShadow(
                color: ColorsConfig.c_14000000,
                offset: Offset(0.0, 0.0), //阴影xy轴偏移量
                blurRadius: 12.0, //阴影模糊程度
                spreadRadius: 0.0 //阴影扩散程度
                )
          ]),
      child: Column(
        children: [
          _wx(),
          Divide(),
          _phone("手机号", "修改"),
          Divide(),
          KsNumber(
            ksState: ksState,
            info: widget.createUserInfoModel,
            ksCode: widget.createUserInfoModel.kuaiShouCode != null
                ? widget.createUserInfoModel.kuaiShouCode
                : "",
            image: widget.createUserInfoModel.kuaiShouQRCode != null &&
                    widget.createUserInfoModel.kuaiShouQRCode.data != null
                ? widget.createUserInfoModel.kuaiShouQRCode.data
                : "",
            setFocus: () {
              return setFocus();
            },
          ),
          Divide(),
          DyNumber(
              dyState: dyState,
              info: widget.createUserInfoModel,
              dyCode: widget.createUserInfoModel.douYinCode != null
                  ? widget.createUserInfoModel.douYinCode
                  : "",
              image: widget.createUserInfoModel.douYinQRCode != null &&
                      widget.createUserInfoModel.douYinQRCode.data != null
                  ? widget.createUserInfoModel.douYinQRCode.data
                  : "",
              setFocus: () {
                return setFocus();
              }),
          Divide(),
          _input("企业微信二维码", "上传"),
        ],
      ),
    );
  }

  bool isUserDraft = false; //是否使用草稿
  Widget _userDraft() {
    return Center(
      child: Container(
          padding: EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(10)),
          height: ScreenUtil().setWidth(30),
          decoration: BoxDecoration(
              color: ColorsConfig.c_fff0d7,
              borderRadius: BorderRadius.all(Radius.circular(20))),
          margin: EdgeInsets.fromLTRB(0, ScreenUtil().setHeight(90), 0, 0),
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              Container(
                margin: EdgeInsets.fromLTRB(0, 0, ScreenUtil().setWidth(8), 0),
                child: InkWell(
                    onTap: () {
                      setState(() {
                        isUserDraft = true;
                        widget.hasDraft = false;
                      });
                    },
                    child: Icon(
                      Icons.cancel,
                      color: ColorsConfig.c_9c8b6b,
                      size: ScreenUtil().setSp(20),
                    )),
              ),
              Container(
                child: Text("有一份未完成草稿，要继续编辑吗？",
                    style: TextStyle(
                        color: ColorsConfig.c_603e00,
                        fontSize: ScreenUtil().setSp(14))),
              ),
              InkWell(
                onTap: () {
                  SpUtil.getData("${SpUtil.user_data}${widget.amwayAda}")
                      .then((value) {
                    Map<String, dynamic> response = json.decode(value);
                    widget.createUserInfoModel =
                        CreateUserInfoModel.fromJson(response);
                    setState(() {
                      nick = widget.createUserInfoModel.nick;
                      _nickController.text = nick;
                      _descController.text =
                          widget.createUserInfoModel.introduce;
                      _wxController.text = widget.createUserInfoModel.wxCode;
                      widget.hasDraft = false;
                      isUserDraft = true;
                    });
                  });
                },
                child: Container(
                  alignment: Alignment.center,
                  width: ScreenUtil().setWidth(65),
                  height: ScreenUtil().setWidth(20),
                  decoration: BoxDecoration(
                      color: ColorsConfig.c_fff0d7,
                      border:
                          Border.all(width: 1, color: ColorsConfig.c_603e00),
                      borderRadius: BorderRadius.all(Radius.circular(11))),
                  child: Text(
                    "使用草稿",
                    style: TextStyle(
                        color: ColorsConfig.c_603e00,
                        fontSize: ScreenUtil().setSp(12)),
                  ),
                ),
              ),
            ],
          )),
    );
  }

  Future<void> getHead(String amwayAda) async {
    var queryParameters = {
      "q": "官方封面",
      "start": 0,
      "rows": 100,
      "sort": "-publishdate"
    };
    var uuid = Uuid();
    var v1 = uuid.v1();
    var heards = {
      "Authorization": FlavorConfig.instance.variables["AppCode"],
      "X-Ca-Nonce": v1,
    };
    var amwayBaseUrl = FlavorConfig.instance.variables["amwayBaseUrl"];
    Options options = Options(headers: heards);
    Dio dio = Dio();
    Response response = await dio.get(amwayBaseUrl + "/images",
        queryParameters: queryParameters, options: options);
    if (response.statusCode == 200) {
      List<GuanfangImage> guanfangImages = [];
      response.data.forEach((element) {
        guanfangImages.add(GuanfangImage.fromJson(element));
      });
    } else {
      print(response.statusCode);
    }
  }
}
